package com.example.mall.mapper;

import com.example.mall.pojo.Attribute;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AttributeMapper {

    @Select("select * from sp_attribute where attr_name=#{attr_name} and attr_sel='many'")
    Attribute selectByName(String name);

    @Select("select * from sp_attribute where attr_name=#{attr_name} and attr_sel='only'")
    Attribute selectByNameOnly(String name);

    @Select("select * from sp_attribute where cat_id=#{cat_id} and attr_sel='many'")
    List<Attribute> selectById(Integer cat_id);

    @Select("select * from sp_attribute where cat_id=#{cat_id} and attr_sel='only'")
    List<Attribute> selectByOnly(Integer cat_id);

    @Select("select * from sp_attribute where attr_id=#{attr_id} and attr_sel='many'")
    Attribute selectByAttrId( Integer attr_id);

    @Select("select * from sp_attribute where attr_id=#{attr_id} and attr_sel='only'")
    Attribute selectByAttrIdOnly( Integer attr_id);

    @Update("update sp_attribute set attr_name=#{attr_name} where attr_id=#{attr_id} and attr_sel='many' ")
    int update(@Param("attr_name") String attr_name,@Param("attr_id") Integer attr_id);

    @Update("update sp_attribute set attr_name=#{attr_name},attr_vals=#{attr_vals} where attr_id=#{attr_id} and attr_sel='only' ")
    int updateByOnly(@Param("attr_name") String attr_name,@Param("attr_vals") String attr_vals, @Param("attr_id") Integer attr_id);

    @Delete("delete from sp_attribute where attr_id=#{attr_id} ")
    int delete(Integer attrId);


    @Insert("insert into sp_attribute(attr_name,attr_sel,cat_id,attr_vals) values(#{attr_name},#{attr_sel},#{cat_id},NULL) ")
    int insertAttr(@Param("attr_name") String attr_name,@Param("attr_sel") String attr_sel, @Param("cat_id") Short cat_id);


}
